﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CodeDynamiksEngine;
using MESCodeFile;
using LiveNotificationSystem;

namespace mes_tublay
{
    public partial class frmRemarks : Form
    {
        frmTreasuryeBPLS x;
        string ap, rf;
        public frmRemarks(frmTreasuryeBPLS p)
        {
            x = p;
            InitializeComponent();
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Load += new EventHandler(frmRemarks_Load);
            btnok.Click += new EventHandler(btnok_Click);
            btncancel.Click += new EventHandler(btncancel_Click);
        }

        void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void btnok_Click(object sender, EventArgs e)
        {
            DialogResult ok = MessageBox.Show("Continue with sending remarks?", "Proceed", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            //Start
            if (ok.Equals(DialogResult.Yes))
            {
                ap = x.appno;
                string t = CurrentUser.NAME;
                string rem = txtremark.Text;
                rf = x.referenceNumber;
                CodeScript cs = new CodeScript("SAVEREMARK");
                cs.Add(CodeIns.DBU_NEW_CORE);
                cs.Add(CodeIns.DBU_CONNECT, Common.CFG.Read("DRIVER"), Common.CFG.Read("DB"),
                Common.CFG.Read("UID"), Common.CFG.Read("PWD"), Common.CFG.Read("SERVER"));
                cs.Add(CodeIns.DBU_INSERT, "tblremarks",
                           new string[] { "fOffice", "fRemark", "fApplicationNumber", "fOfficer" },
                           new object[] { "'TREASURY_DEPT_TREASURER'", "'" + rem + "'", "'" + ap + "'", "'" + t + "'" });
                cs.Add(CodeIns.DBU_END);

                CodeProcessor cp = new CodeProcessor(ThreadingMode.Exclusive);
                cp.ProcessCompleted += new EventHandler(delegate
                {
                    cp.SafeCall(this, delegate
                    {
                        if (cp.State == ProcessorFlag.DataRdyErr ||
                            cp.State == ProcessorFlag.Error ||
                            cp.State == ProcessorFlag.ReadyErr)
                        {
                            Confirm.Error("Sampler", cp.GetProcessorMessage);
                            return;
                        }
                    });
                });
                cp.Run(cs);
                Common.NOTIFY.Push("TREASURY_DEPT_ASSESSOR", "New Business Permit Application: " + ap + "- Adjust Assessment", new string[] { "" + ap, rf, "TREASURER"});
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();

            }
            
            //End
        }

        void frmRemarks_Load(object sender, EventArgs e)
        {
            lblappnum.Text = x.appno;
        }
    }
}
